/**
 * 
 */
package com.broadtext.rms.system.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.broadtext.common.exp.DaoException;
import com.broadtext.common.repository.EntityDao;
import com.broadtext.rms.system.dao.ISysDictDao;
import com.broadtext.rms.system.model.SysDict;

/**
 * 
 * <p>ClassName: SysDictDaoImpl</p>
 * <p>Description: 字典管理Dao</p>
 * <p>Author: xieshuang</p>
 * <p>Date: 2017-4-5</p>
 */
@Repository("sysDictDao")
public class SysDictDaoImpl extends EntityDao<SysDict> implements ISysDictDao {

    /**
     * 
     * <p>
     * Description: 获取所有字典
     * </p>
     * 
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectAllDict() throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByQuery("com.broadtext.rms.system.model.SysDict.selectAllDict", null);
        return list;
    }

    /**
     * 
     * <p>
     * Description: 获取所有字典
     * </p>
     * 
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectAdminDict() throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByQuery("com.broadtext.rms.system.model.SysDict.selectAdminDict", null);
        return list;
    }

    /**
     * 
     * <p>
     * Description: 根据用户名获取用户所有字典
     * </p>
     * 
     * @param loginName 用户名
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectDictByLoginName(String loginName) throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByProperty("com.broadtext.rms.system.model.SysDict.selectDictByLoginName", loginName);
        return list;
    }

    /**
     * 
     * <p>
     * Description: 根据用户名获取用户所有字典
     * </p>
     * 
     * @param userId 用户ID
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectDictByUserId(String userId) throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByProperty("com.broadtext.rms.system.model.SysDict.selectDictByUserId", userId);
        return list;
    }

    /**
     * 
     * <p>
     * Description: 根据dictId查找字典
     * </p>
     * 
     * @param dictId 参数
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectDictByDictId(String dictId) throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByProperty("com.broadtext.rms.system.model.SysDict.selectDictByDictId", dictId);
        return list;
    }

    /**
     * 
     * <p>
     * Description: 根据查询查找资源
     * </p>
     * 
     * @param map 参数
     * @return List<SysDict>
     * @throws DaoException daoException
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<SysDict> selectDictByMap(Map<String, Object> map) throws DaoException {
        List<SysDict> list;
        list = new ArrayList<SysDict>();
        list = super.findByProperty("com.broadtext.rms.system.model.SysDict.selectDictByMap", map);
        return list;
    }

    @SuppressWarnings("unchecked")
    @Override
    public String selectDictByPro(String parentKey, String dictKey) throws DaoException {
        Map<String, Object> map;
        map = new HashMap<String, Object>();
        map.put("parentKey", parentKey);
        map.put("dictKey", dictKey);
        List<SysDict> list;
        list = super.findByProperty("com.broadtext.rms.system.model.SysDict.selectDictByPro", map);
        if (list.size() != 0 && !"".equals(list.get(0).getDictValue())) {
            return list.get(0).getDictValue();
        }
        return null;
    }

}
